﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRM.DAL.DAO;
using HRM.DAL.Gateway;

namespace HRM.BLL
{
    public class LeaveStatusManager
    {
        LeaveStatusGateway gateway=new LeaveStatusGateway();
        public bool SaveLeaveStatus(int EmpId)
        {
            Leave leave=new Leave();
            LeaveManager leaveManager=new LeaveManager();
            leave = leaveManager.GetLeaveSettings();
            return gateway.SaveLeaveStatus(EmpId,leave);
        }
        public LeaveStatus GetEmployeeLeaveStatus(Code code)
        {
            EmployeeManager employeeManager=new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(code);
            return gateway.GetEmployeeLeaveStatus(empId);
        }

        public bool UpdateEmployeeLeaveStatus(Code code, LeaveApplication leaveType)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(code);
            LeaveStatus leaveStatus=new LeaveStatus();
            leaveStatus= gateway.GetEmployeeLeaveStatus(empId);

            switch (leaveType.LeaveType)
            {
                case "Earn Leave":leaveStatus.EarnLeave = leaveStatus.EarnLeave - leaveType.TotalDays;break;
                case "Sick Leave": leaveStatus.SickLeave = leaveStatus.SickLeave - leaveType.TotalDays; break;
                case "Casual Leave": leaveStatus.CasualLeave = leaveStatus.CasualLeave - leaveType.TotalDays; break;
                case "Others": leaveStatus.Others = leaveStatus.Others - leaveType.TotalDays; break;
            }

            return gateway.UpdateEmployeeLeaveStatus(empId, leaveStatus);
        }
     
    }
}